﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="Pool.cs" company="">
//   
// </copyright>
// <summary>
//   Defines the Pool type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
namespace F5.BigIp.LocalTrafficManager.Interfaces
{
    using System;
    using System.Collections.Generic;
    using System.Linq;

    /// <summary>
    ///     The pool.
    /// </summary>
    public class Pool : NotifyPropertyChanged, IPool
    {
        #region Fields

        /// <summary>
        ///     The LoadBalancer.
        /// </summary>
        private LoadBalancer loadBalancer;

        /// <summary>
        ///     The members.
        /// </summary>
        private IList<IPoolMember> members;

        /// <summary>
        ///     The name.
        /// </summary>
        private string name;

        /// <summary>
        ///     The status.
        /// </summary>
        private PoolStatus status;

        #endregion

        #region Constructors and Destructors

        /// <summary>Initializes a new instance of the <see cref="Pool"/> class.</summary>
        /// <param name="name">The name.</param>
        /// <param name="loadBalancer">The LoadBalancer.</param>
        /// <exception cref="ArgumentNullException">is thrown when a method is invoked and at least one of the passed arguments is null but should never be null.</exception>
        public Pool(string name, LoadBalancer loadBalancer)
        {
            if (loadBalancer == null)
            {
                throw new ArgumentNullException("loadBalancer");
            }

            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException("name");
            }

            this.loadBalancer = loadBalancer;
            this.name = name;
        }

        #endregion

        #region Public Properties

        /// <summary>
        ///     Gets or sets the LoadBalancer.
        /// </summary>
        public LoadBalancer LoadBalancer
        {
            get
            {
                return this.loadBalancer;
            }

            set
            {
                this.loadBalancer = value;
                this.OnPropertyChanged();
            }
        }

        /// <summary>
        ///     Gets the display name.
        /// </summary>
        public string DisplayName
        {
            get
            {
                return this.name.Contains('/') ?
                    this.Name.Split('/')[2] :
                    this.name; // TODO: (backward compatibility) move to implementation (adapter) class
            }
        }

        /// <summary>
        ///     Gets or sets the members.
        /// </summary>
        public IList<IPoolMember> Members
        {
            get
            {
                return this.members;
            }

            set
            {
                this.members = value;
                this.OnPropertyChanged();
            }
        }

        /// <summary>
        ///     Gets or sets the name.
        /// </summary>
        public string Name
        {
            get
            {
                return this.name;
            }

            set
            {
                this.name = value;
                this.OnPropertyChanged();
            }
        }

        /// <summary>
        ///     Gets or sets the status.
        /// </summary>
        public PoolStatus Status
        {
            get
            {
                return this.status;
            }

            set
            {
                this.status = value;
                this.OnPropertyChanged();
            }
        }

        #endregion
    }
}